package com.robgfx.coalex.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;

public class DictionaryView extends Composite {
	public DictionaryView(Composite parent) {
		super(parent, SWT.NONE);
		buildGUI();
	}

	private void buildGUI() {

		setLayout(new GridLayout());
		setBackgroundMode(SWT.INHERIT_FORCE);
		GridData searchData = new GridData();
		searchData.grabExcessHorizontalSpace = true;
		searchData.horizontalAlignment = GridData.FILL;
		Text searchWidget = new Text(this, SWT.SINGLE);
		searchWidget.setLayoutData(searchData);

		GridData listData = new GridData();
		listData.grabExcessHorizontalSpace = true;
		listData.horizontalAlignment = GridData.FILL;
		listData.grabExcessVerticalSpace = true;
		listData.verticalAlignment = GridData.FILL;
		final Color bgColor = new Color(getDisplay(), 255, 0, 255);
		// listBox.set
		final Canvas listWrapper = new Canvas(this, SWT.NONE);
		listWrapper.setLayoutData(listData);
		// listWrapper.add
		listWrapper.addPaintListener(new PaintListener() {

			public void paintControl(PaintEvent e) {
				e.gc.setBackground(bgColor);
				e.gc.setAlpha(100);
				e.gc.fillRoundRectangle(0, 0, listWrapper.getSize().x,
						listWrapper.getSize().y, 20, 20);
			}

		});
		List listBox = new List(listWrapper,SWT.NO_BACKGROUND);
		GridData listBoxData = new GridData();
		listBoxData.grabExcessHorizontalSpace = true;
		listBoxData.grabExcessVerticalSpace = true;
		listBoxData.verticalIndent = 20;
		listBoxData.horizontalIndent = 20;
		listBox.setLayoutData(listBoxData);
		listBox.add("STRING1");
		listBox.add("STRING1");
		listBox.add("STRING1");
		listBox.add("STRING1");
		listBox.add("STRING1");
		addWord(listWrapper, "Word", "Definition");
		listWrapper.setLayout(new GridLayout());
		
	}

	private void addWord(Canvas listWrapper, String word, String definition) {
		GridData data = new GridData();
		data.grabExcessHorizontalSpace = true;
		data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
		data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
		// create the label:
		Label l = new Label(listWrapper,SWT.WRAP);
		l.setText(word + " " + definition);
	}
}
